using System;
using System.Data;
using System.Data.SqlClient;

using EntLibEC.Cmn;
using EntLibEC.Info.Basic;


namespace EntLibEC.Dac.Basic
{
	/// <summary>
	/// Summary description for VendorDac.
	/// </summary>
	public class VendorDac
	{
		
		public VendorDac()
		{
		}

		public int Insert(VendorInfo oParam)
		{
			string sql = @"INSERT INTO Ent_Vendor
                            (
                            SysNo, VendorID, VendorName, EnglishName, 
                            BriefName, VendorType, District, Address, 
                            Zip, Phone, Fax, Email, 
                            Site, Bank, Account, TaxNo, 
                            Contact, Comment, Note, 
                            Status ,RMAPolicy,PayPeriod
                            )
                            VALUES (
                            @SysNo, @VendorID, @VendorName, @EnglishName, 
                            @BriefName, @VendorType, @District, @Address, 
                            @Zip, @Phone, @Fax, @Email, 
                            @Site, @Bank, @Account, @TaxNo, 
                            @Contact, @Comment, @Note, 
                            @Status , @RMAPolicy , @PayPeriod
                            )";
			SqlCommand cmd = new SqlCommand(sql);

			SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4);
			SqlParameter paramVendorID = new SqlParameter("@VendorID", SqlDbType.NVarChar,20);
			SqlParameter paramVendorName = new SqlParameter("@VendorName", SqlDbType.NVarChar,100);
			SqlParameter paramEnglishName = new SqlParameter("@EnglishName", SqlDbType.NVarChar,100);
			SqlParameter paramBriefName = new SqlParameter("@BriefName", SqlDbType.NVarChar,50);
			SqlParameter paramVendorType = new SqlParameter("@VendorType", SqlDbType.Int,4);
			SqlParameter paramDistrict = new SqlParameter("@District", SqlDbType.NVarChar,100);
			SqlParameter paramAddress = new SqlParameter("@Address", SqlDbType.NVarChar,100);
			SqlParameter paramZip = new SqlParameter("@Zip", SqlDbType.NVarChar,10);
			SqlParameter paramPhone = new SqlParameter("@Phone", SqlDbType.NVarChar,50);
			SqlParameter paramFax = new SqlParameter("@Fax", SqlDbType.NVarChar,50);
			SqlParameter paramEmail = new SqlParameter("@Email", SqlDbType.NVarChar,50);
			SqlParameter paramSite = new SqlParameter("@Site", SqlDbType.NVarChar,100);
			SqlParameter paramBank = new SqlParameter("@Bank", SqlDbType.NVarChar,50);
			SqlParameter paramAccount = new SqlParameter("@Account", SqlDbType.NVarChar,50);
			SqlParameter paramTaxNo = new SqlParameter("@TaxNo", SqlDbType.NVarChar,50);
			SqlParameter paramContact = new SqlParameter("@Contact", SqlDbType.NVarChar,20);
			SqlParameter paramComment = new SqlParameter("@Comment", SqlDbType.NVarChar,20);
			SqlParameter paramNote = new SqlParameter("@Note", SqlDbType.NVarChar,500);
			SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int,4);
			SqlParameter paramRMAPolicy = new SqlParameter("@RMAPolicy", SqlDbType.NVarChar,500);
			SqlParameter paramPayPeriod = new SqlParameter("@PayPeriod", SqlDbType.Int,4);

			paramSysNo.Value = oParam.SysNo;
			paramVendorID.Value = oParam.VendorID;
			paramVendorName.Value = oParam.VendorName;
			
			if ( oParam.EnglishName != AppConst.StringNull)
				paramEnglishName.Value = oParam.EnglishName;
			else
				paramEnglishName.Value = System.DBNull.Value;
			if ( oParam.BriefName != AppConst.StringNull)
				paramBriefName.Value = oParam.BriefName;
			else
				paramBriefName.Value = System.DBNull.Value;

			paramVendorType.Value = oParam.VendorType;

			if ( oParam.District != AppConst.StringNull)
				paramDistrict.Value = oParam.District;
			else
				paramDistrict.Value = System.DBNull.Value;
			if ( oParam.Address != AppConst.StringNull)
				paramAddress.Value = oParam.Address;
			else
				paramAddress.Value = System.DBNull.Value;
			if ( oParam.Zip != AppConst.StringNull)
				paramZip.Value = oParam.Zip;
			else
				paramZip.Value = System.DBNull.Value;
			if ( oParam.Contact != AppConst.StringNull)
				paramContact.Value = oParam.Contact;
			else
				paramContact.Value = System.DBNull.Value;
			if ( oParam.Phone != AppConst.StringNull)
				paramPhone.Value = oParam.Phone;
			else
				paramPhone.Value = System.DBNull.Value;
			if ( oParam.Fax != AppConst.StringNull)
				paramFax.Value = oParam.Fax;
			else
				paramFax.Value = System.DBNull.Value;
			if ( oParam.Email != AppConst.StringNull)
				paramEmail.Value = oParam.Email;
			else
				paramEmail.Value = System.DBNull.Value;
			if ( oParam.Site != AppConst.StringNull)
				paramSite.Value = oParam.Site;
			else
				paramSite.Value = System.DBNull.Value;
			if ( oParam.Bank != AppConst.StringNull)
				paramBank.Value = oParam.Bank;
			else
				paramBank.Value = System.DBNull.Value;
			if ( oParam.Account != AppConst.StringNull)
				paramAccount.Value = oParam.Account;
			else
				paramAccount.Value = System.DBNull.Value;
			if ( oParam.TaxNo != AppConst.StringNull)
				paramTaxNo.Value = oParam.TaxNo;
			else
				paramTaxNo.Value = System.DBNull.Value;
			if ( oParam.Comment != AppConst.StringNull)
				paramComment.Value = oParam.Comment;
			else
				paramComment.Value = System.DBNull.Value;
			if ( oParam.Note != AppConst.StringNull)
				paramNote.Value = oParam.Note;
			else
				paramNote.Value = System.DBNull.Value;

			if ( oParam.RMAPolicy != AppConst.StringNull)
				paramRMAPolicy.Value = oParam.RMAPolicy;
			else
				paramRMAPolicy.Value = System.DBNull.Value;

			if ( oParam.PayPeriod != AppConst.IntNull)
				paramPayPeriod.Value = oParam.PayPeriod;
			else
				paramPayPeriod.Value = System.DBNull.Value;

			paramStatus.Value = oParam.Status;

			cmd.Parameters.Add(paramSysNo);
			cmd.Parameters.Add(paramVendorID);
			cmd.Parameters.Add(paramVendorName);
			cmd.Parameters.Add(paramEnglishName);
			cmd.Parameters.Add(paramBriefName);
			cmd.Parameters.Add(paramVendorType);
			cmd.Parameters.Add(paramDistrict);
			cmd.Parameters.Add(paramAddress);
			cmd.Parameters.Add(paramZip);
			cmd.Parameters.Add(paramPhone);
			cmd.Parameters.Add(paramFax);
			cmd.Parameters.Add(paramEmail);
			cmd.Parameters.Add(paramSite);
			cmd.Parameters.Add(paramBank);
			cmd.Parameters.Add(paramAccount);
			cmd.Parameters.Add(paramTaxNo);
			cmd.Parameters.Add(paramContact);
			cmd.Parameters.Add(paramComment);
			cmd.Parameters.Add(paramNote);
			cmd.Parameters.Add(paramStatus);
			cmd.Parameters.Add(paramRMAPolicy);
			cmd.Parameters.Add(paramPayPeriod);

			return SqlHelper.ExecuteNonQuery(cmd);
		}

		public int Update(VendorInfo oParam)
		{
			string sql = @"UPDATE Ent_Vendor SET 
                            VendorID=@VendorID, 
                            VendorName=@VendorName, EnglishName=@EnglishName, 
                            BriefName=@BriefName, VendorType=@VendorType, 
                            District=@District, Address=@Address, 
                            Zip=@Zip, Phone=@Phone, 
                            Fax=@Fax, Email=@Email, 
                            Site=@Site, Bank=@Bank, 
                            Account=@Account, TaxNo=@TaxNo, 
                            Contact=@Contact, Comment=@Comment, 
                            Note=@Note, Status=@Status , RMAPolicy=@RMAPolicy , PayPeriod=@PayPeriod
                            WHERE SysNo=@SysNo";
			SqlCommand cmd = new SqlCommand(sql);

			SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4);
			SqlParameter paramVendorID = new SqlParameter("@VendorID", SqlDbType.NVarChar,20);
			SqlParameter paramVendorName = new SqlParameter("@VendorName", SqlDbType.NVarChar,100);
			SqlParameter paramEnglishName = new SqlParameter("@EnglishName", SqlDbType.NVarChar,100);
			SqlParameter paramBriefName = new SqlParameter("@BriefName", SqlDbType.NVarChar,50);
			SqlParameter paramVendorType = new SqlParameter("@VendorType", SqlDbType.Int,4);
			SqlParameter paramDistrict = new SqlParameter("@District", SqlDbType.NVarChar,100);
			SqlParameter paramAddress = new SqlParameter("@Address", SqlDbType.NVarChar,100);
			SqlParameter paramZip = new SqlParameter("@Zip", SqlDbType.NVarChar,10);
			SqlParameter paramPhone = new SqlParameter("@Phone", SqlDbType.NVarChar,50);
			SqlParameter paramFax = new SqlParameter("@Fax", SqlDbType.NVarChar,50);
			SqlParameter paramEmail = new SqlParameter("@Email", SqlDbType.NVarChar,50);
			SqlParameter paramSite = new SqlParameter("@Site", SqlDbType.NVarChar,100);
			SqlParameter paramBank = new SqlParameter("@Bank", SqlDbType.NVarChar,50);
			SqlParameter paramAccount = new SqlParameter("@Account", SqlDbType.NVarChar,50);
			SqlParameter paramTaxNo = new SqlParameter("@TaxNo", SqlDbType.NVarChar,50);
			SqlParameter paramContact = new SqlParameter("@Contact", SqlDbType.NVarChar,20);
			SqlParameter paramComment = new SqlParameter("@Comment", SqlDbType.NVarChar,20);
			SqlParameter paramNote = new SqlParameter("@Note", SqlDbType.NVarChar,500);
			SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int,4);
			SqlParameter paramRMAPolicy = new SqlParameter("@RMAPolicy", SqlDbType.NVarChar,500);
			SqlParameter paramPayPeriod = new SqlParameter("@PayPeriod", SqlDbType.Int,4);

			paramSysNo.Value = oParam.SysNo;
			paramVendorID.Value = oParam.VendorID;
			paramVendorName.Value = oParam.VendorName;
			
			if ( oParam.EnglishName != AppConst.StringNull)
				paramEnglishName.Value = oParam.EnglishName;
			else
				paramEnglishName.Value = System.DBNull.Value;
			if ( oParam.BriefName != AppConst.StringNull)
				paramBriefName.Value = oParam.BriefName;
			else
				paramBriefName.Value = System.DBNull.Value;

			paramVendorType.Value = oParam.VendorType;

			if ( oParam.District != AppConst.StringNull)
				paramDistrict.Value = oParam.District;
			else
				paramDistrict.Value = System.DBNull.Value;
			if ( oParam.Address != AppConst.StringNull)
				paramAddress.Value = oParam.Address;
			else
				paramAddress.Value = System.DBNull.Value;
			if ( oParam.Zip != AppConst.StringNull)
				paramZip.Value = oParam.Zip;
			else
				paramZip.Value = System.DBNull.Value;
			if ( oParam.Contact != AppConst.StringNull)
				paramContact.Value = oParam.Contact;
			else
				paramContact.Value = System.DBNull.Value;
			if ( oParam.Phone != AppConst.StringNull)
				paramPhone.Value = oParam.Phone;
			else
				paramPhone.Value = System.DBNull.Value;
			if ( oParam.Fax != AppConst.StringNull)
				paramFax.Value = oParam.Fax;
			else
				paramFax.Value = System.DBNull.Value;
			if ( oParam.Email != AppConst.StringNull)
				paramEmail.Value = oParam.Email;
			else
				paramEmail.Value = System.DBNull.Value;
			if ( oParam.Site != AppConst.StringNull)
				paramSite.Value = oParam.Site;
			else
				paramSite.Value = System.DBNull.Value;
			if ( oParam.Bank != AppConst.StringNull)
				paramBank.Value = oParam.Bank;
			else
				paramBank.Value = System.DBNull.Value;
			if ( oParam.Account != AppConst.StringNull)
				paramAccount.Value = oParam.Account;
			else
				paramAccount.Value = System.DBNull.Value;
			if ( oParam.TaxNo != AppConst.StringNull)
				paramTaxNo.Value = oParam.TaxNo;
			else
				paramTaxNo.Value = System.DBNull.Value;
			if ( oParam.Comment != AppConst.StringNull)
				paramComment.Value = oParam.Comment;
			else
				paramComment.Value = System.DBNull.Value;
			if ( oParam.Note != AppConst.StringNull)
				paramNote.Value = oParam.Note;
			else
				paramNote.Value = System.DBNull.Value;

			if ( oParam.RMAPolicy != AppConst.StringNull)
				paramRMAPolicy.Value = oParam.RMAPolicy;
			else
				paramRMAPolicy.Value = System.DBNull.Value;

			if ( oParam.PayPeriod != AppConst.IntNull)
				paramPayPeriod.Value = oParam.PayPeriod;
			else
				paramPayPeriod.Value = System.DBNull.Value;

			paramStatus.Value = oParam.Status;

			cmd.Parameters.Add(paramSysNo);
			cmd.Parameters.Add(paramVendorID);
			cmd.Parameters.Add(paramVendorName);
			cmd.Parameters.Add(paramEnglishName);
			cmd.Parameters.Add(paramBriefName);
			cmd.Parameters.Add(paramVendorType);
			cmd.Parameters.Add(paramDistrict);
			cmd.Parameters.Add(paramAddress);
			cmd.Parameters.Add(paramZip);
			cmd.Parameters.Add(paramPhone);
			cmd.Parameters.Add(paramFax);
			cmd.Parameters.Add(paramEmail);
			cmd.Parameters.Add(paramSite);
			cmd.Parameters.Add(paramBank);
			cmd.Parameters.Add(paramAccount);
			cmd.Parameters.Add(paramTaxNo);
			cmd.Parameters.Add(paramContact);
			cmd.Parameters.Add(paramComment);
			cmd.Parameters.Add(paramNote);
			cmd.Parameters.Add(paramStatus);
			cmd.Parameters.Add(paramRMAPolicy);
			cmd.Parameters.Add(paramPayPeriod);

			return SqlHelper.ExecuteNonQuery(cmd);
		}
	}
}
